package com.bbs.config;

import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.LinkedHashMap;
import java.util.Map;

@Configuration
public class shiroConfig {
    //设置shiro的安全拦截
    //设置获取主体对象的配置
    //获取领域对象
    @Bean
    public ShiroFilterFactoryBean factoryBean() {
        ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();
        Map<String, String> map = new LinkedHashMap<>();
        map.put("/page/admin/addAdmin","perms[admin:add]");
        map.put("/page/admin/*","authc");
        bean.setFilterChainDefinitionMap(map);
        bean.setUnauthorizedUrl("/admin/noauthor");
        bean.setLoginUrl("/page/login");
        bean.setSecurityManager(getSecurityManager());
        return bean;
    }


    @Bean
    public DefaultWebSecurityManager getSecurityManager() {
        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
        securityManager.setRealm(getRealm());
        return securityManager;
    }

    @Bean
    public adminRealm getRealm() {
        return new adminRealm();
    }
}
